<template>
  <el-dialog :close-on-click-modal="false" modal-append-to-body lock-scroll top="10%" :title="$t('public.tip')" :visible.sync="dialogDeleteFormVisible" width="30%">
    <span>{{$t('km.ifDeleteCata')}}</span>
    <span slot="footer" class="dialog-footer">
        <el-button @click.stop="dialogDeleteFormVisible = false" class="primary_btn">{{$t('public.cancel')}}</el-button>
        <el-button type="primary" @click.stop="confirmDelete" class="primary_btn">{{$t('public.confirm')}}</el-button>
      </span>
  </el-dialog>
</template>
<script>
  export default {
    name: 'DeleteCatalogue',
    props: {
      model: Object,
      kmType: String
    },
    data () {
      return {
        dialogDeleteFormVisible: false,
        formStacked: {
          name: '',
          region: '',
          type: ''
        },
        formLabelWidth: '120px'
      }
    },
    methods: {
      stop () {
        // 阻止冒泡
      },
      open () {
        this.dialogDeleteFormVisible = true
      },
      confirmDelete () {
        if (this.model.childs && this.model.childs.length !== 0) {
          this.$message.error(this.$t('km.hasSubCata'))
        } else {
          let data = {
            id: this.model._id,
            kmType: this.model.kmType
          }
          this.$store.dispatch('delCatalog', data).then((res) => {
            this.dialogDeleteFormVisible = false
            if (res.success) {
              this.$store.commit('km/REFRESH_TREE', Math.random())
              // 如果删除当前目录则跳到最近更新
              if (data.id === this.$route.path.split('/')[4]) {
                this.$router.push('/index/km/' + this.kmType + '/curupdate')
                this.$store.commit('km/REFRESH_RIGHT', {type: 'init'})
              }
            }else{
              if(res.message == 'no deleteCatalog permission!') this.$message.error("权限不足,删除失败")
            }
          })
        }
      }
    }
  }
</script>
<style lang="stylus" scoped>
  .sort
    width 130px
    float left
</style>

